/**
 *@title
 *@author huahuadavids
 *@date 2020/4/11
 */

import React   from 'react';
import actions from "../store/actions/counter"
import connect from "../react-redux/connect"
// 用来实现action和dispatch的绑定

 class Counter extends React.Component {
  constructor(props) {
    super(props);
  }


  render() {
    return (
      <div id="Counter" style={{border: "1px solid #111"}} >
        <p>{this.props.number}</p>
        <button onClick={this.props.increment} >+</button>
        <button onClick={this.props.decrement} >-</button>
        <button onClick={() => {
          setTimeout(() => {this.props.increment()}, 1000)
        }}>一秒后再加</button>
      </div>
    )
  }
}

// let mapStateToProps = state => state.counter;

// 第一种
// let mapDispatchToProps = dispatch => ({
//   // increment: () => dispatch({type: types.INCREMENT})
//   increment: () => dispatch({type: actions.increment()})
//
// });

// 第二种 connect会默认调用 bindActionCreator 实现绑定
// let mapDispatchToProps = actions;

export default connect(
  state => state.counter,
  actions
)(Counter)